/*!
 * X weibo JavaScript Library v1.1
 * http://x.weibo.com/
 * 
 * Copyright 2010 SINA Inc.
 * Date: 2010/10/28 21:22:06
 */

(function(X){

if(!window.__debug)
    __debug = false;

var 
    localDomain  = location.hostname,
    domainReg = /:\/\/(.[^\/]+)/,
    Util = X.util,
    api_spots = 'api/spots/';

var XwbRequest = {
    
/**
 * @class Xwb.ax.RequestConfig
 * @extends Xwb.ax.AjaxConfig
 */
 
 /**
  * @cfg {Function} success
  * @param {Xwb.ax.ResponseDefinition} data
  */

/**
 * @class Xwb.request
 * Xwb库数据层API。<br/>
 * 发起任何请求前请先执行初始化{@link #init}。
 * @singleton
 */

/**
 *  初始化请求。发起任何请求前请先初始化。
 * @param {String} serverBaseUrl 服务器URL.
 * @return this
 */
    init : function(server){
        this.basePath = server;
        return this;
    },
    
/**
 * 发起一个请求。<br>请求不必理会是否跨域，系统会判断是否同域调用ajax或JSONP请求。
 * @param {Xwb.ax.RequestConfig} config
 * @return {Connector} connector XMLHttpRequest|SCRIPT
 */
    direct : function(cfg){
        if(!cfg)
            cfg = {};
            
        // make a success handler wrapper
        var handler = cfg.success, connector;
        cfg.success = function(data, connector){
            
            var e = new ( cfg.responseDefinition || XwbRequest.DefaultResponseDefinition ) (data, cfg, connector);
            
            if(__debug) console.log('req e:', e);
            
            if(cfg.scope)
                handler.call(cfg.scope, e);
            else handler(e);
            
            data = null;
            e = null;
            connector = null;
        };
        
        //服务器返回错误
        if (!cfg.failure) {
            cfg.failure = function(respText, xhr) {
                data = {
                    rst : respText,
                    errno : -999,
                    error : '网络错误'
                };
                
                var e = new ( cfg.responseDefinition || XwbRequest.DefaultResponseDefinition ) (data, cfg, connector);
                
                if(cfg.scope)
                    handler.call(cfg.scope, e);
                else handler(e);
                
                data = null;
                e = null;
                connector = null;
            }
        }
        
        // check domain the same
        var domain = cfg.url.match(domainReg);
        connector = !domain || domain[1] == localDomain ? Util.ajax(cfg) : Util.jsonp(cfg);
        return connector;
    },
    
/**
 * 利用给定参数发起一个POST请求
 * <code><pre>
    // POST
    Xwb.request.post(
        'http://demo.rayli.com.cn/?m=action.getCounts',
        {ids:'3042338323,3042296891'},
        function(e){
            if(e.isOk()){
                console.log(e.getRaw());
            }
        }
    );
   </pre></code>
 * @param {String} url
 * @param {Object} data
 * @param {Function} successCallback
 * @param {Xwb.ax.RequestConfig} config
 * @return {Connector} connector XMLHttpRequest|SCRIPT
 */
    postReq : function(url, data, success, cfg){
        !cfg && (cfg = {});
        cfg.method = 'POST';
        return this.q(url, data, success, cfg);
    },
    
    getReq : function(url, data, success, cfg) {
        !cfg && (cfg = {});
        cfg.method = 'GET';
        return this.q(url, data, success, cfg);
    },

/**
 * 利用给定参数发起一个请求。
 * q是query的缩写。 
 * <code><pre>
    // JSONP
    Xwb.request.q(
        'http://bbs.rayli.com.cn/api/sinax.php',
        {
            action : 'sinalogin',
            name   : 'yourname',
            pwd    : 'youpassword'
        },
        function(e){
            if(e.isOk()){
                console.log(e.getRaw());
            }
        },
        
        // 默认 'jsonp'，可根据具体目标而设置
        {jsonp:'jscallback'}
    );
   </pre></code>
 * @param {String} url
 * @param {Object} data
 * @param {Function} successCallback
 * @param {Xwb.ax.RequestConfig} config
 * @return {Connector} connector XMLHttpRequest|SCRIPT
 */
    q : function(url, data, success, cfg){
        !cfg && (cfg = {});
        cfg.url = url;
        // merge data
        if(cfg.data)
            Util.extend(cfg.data, data);
        else cfg.data = data;
        cfg.success = success;
        return this.direct(cfg);
    },
    
    basePath : '/',
    
/**
 * 发起XWB的action请求
 * @param {String} actionName
 * @param {Xwb.ax.RequestConfig} config
 * @return {Connector} connector XMLHttpRequest|SCRIPT
 */
    act : function(module,name, data, success, cfg){
        !cfg && (cfg = {});
        var url = cfg.url || this.jsAPI(module, name, '', cfg.prefix);
        
        !cfg.method && (cfg.method = 'POST');
        
        return this.q(url, data, function(){
            success && success.apply(this, arguments);
            // 数据层发送 act.开头的各种action事件
            var arg = [module+'.'+name];
            for(var i=0,len=arguments.length;i<len;i++)
                arg.push(arguments[i]);
            X.fire.apply(X, arg);
        }, cfg);
    },
	
    
/**
 * 创建Xwb页面链接
 * @param {String} moduleName
 * @param {String} actionName
 * @param {String} [queryString]
 * @param {String} [entry]
 * @return {String}
 */
    mkUrl : function(module, action, queryStr, entry){
        var params = (entry||'index.php')+'?m=' + module;
        if (action)
            params += '.' + action;

        if (queryStr){
          params += '&';
          typeof queryStr === 'string' ?  params += queryStr : params+=Util.queryString(queryStr);
        }
        return this.basePath + params;
    },
    
/**
 * 获得api/weibo/请求URL
 * @param {String} moduleName
 * @param {String} actionName
 * @param {String} [queryString]
 */
    apiUrl : function(module, action, queryStr, prefix){
        !prefix && (prefix = 'api/weibo/');
        return this.mkUrl(prefix + module, action, queryStr);
    },
	/**
 * 获得api/weibo/请求URL
 * @param {String} moduleName
 * @param {String} actionName
 * @param {String} [queryString]
 */
 
    jsAPI : function(module, action, queryStr, prefix){
        !prefix && (prefix = 'jsApi/');
        return this.mkUrl(prefix + module, action, queryStr);
    },
    
    url : {
        zyj : function(apiname) {
            return XwbRequest.jsAPI('ziyoujiApi', apiname);
        }
    },

/**
 * 解析原始返回的数据，很少会用到本方法，除非要手动解释返回的JSON数据。
 * @param {Object} rawData
 * @return {Xwb.request.DefaultResponseDefinition}
 */
    parseProtocol : function(ret){
        return new XwbRequest.DefaultResponseDefinition( ret );
    },
    
    event : function(name, data, success, cfg) {
        var url = this.mkUrl('event', name);
        this.postReq(url, data, success, cfg);
    },
    
// ------------------------------------
// XWB具体数据请求API
// ------------------------------------

/**
 * 发布微博
 * @param {String} text 微博内容
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {String} pic
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    post : function(text, fn, pic, cfg){
        var data = {text:text};
        if(pic)
            data.pic = pic;
        XwbRequest.act('update', data, fn, cfg);
    },
    
/**
 * 分享图片微博
 * @param {String} text 微博内容
 * @param {String} picId 图片pid
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    postImgText : function(text, picId, fn, cfg){
        XwbRequest.act('upload', {text:text, pic:picId}, fn, cfg);
    },
    
/**
 * 转发微博
 * @param {String} postId  微博id
 * @param {String} text    微博内容
 * @param {String} userList   同时作为userList的评论发布，用户ID用逗号分隔
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    repost : function(id, text, uids, fn, cfg){
        XwbRequest.act('repost', {
            id:id, 
            text:text, 
            rtids : uids
          }, fn, cfg
        );
    },

/**
 * 删除微博
 * @param {String} postId 微博id
 * @param {Number|String} v 是否正在审核中的
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    del : function(id, v, fn, cfg){
        XwbRequest.act('feedApi','delete', {fid:id, v: v}, fn, cfg);
    },

/**
 * 评论微博
 * @param {String} postId 微博id
 * @param {String} text 微博内容
 * @param {Number} forward 是否作为一条新微博发布，1是，0否
 * @param {Number} headPictureType 评论显现头像类型, 默认是1，30大小的头像，2，50大小的头像
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    comment : function(id, text, forward, hpt, fn, cfg){
        XwbRequest.postReq(XwbRequest.jsAPI('feedApi','comment_post'), {
            fid:id,
            text:text,
            forward : forward,
            type:hpt
           }, fn, cfg
        );
    },
/**
 * 评论游记
 * @param {String} postId 游记id
 * @param {String} text 游记评论内容
 * @param {Number} forward 是否作为一条新微博发布，1是，0否
 * @param {Number} headPictureType 评论显现头像类型, 默认是1，30大小的头像，2，50大小的头像
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    youjiComment : function(id, text, forward, hpt, fn, cfg){
		this.act('commentsApi', 'comment', {
            id:id,
            text:text,
            forward : forward,
            type:hpt
           }, fn, cfg
        );
    },
/**
 * @param {String} id 评论微博id
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    delComment : function(id , rid , fn, cfg){
        XwbRequest.act('feedApi','comment_delete', {comment_id:id}, fn, cfg);
    },
/**
 * @param {String} id 本地评论id
 * @param {String} rid 评论微博id
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    youjiDelComment : function(id , rid , fn, cfg){
        XwbRequest.act('commentsApi','comment_destroy', { id:id , rid : rid }, fn, cfg);
    },    
/**
 * 回复微博评论
 * @param {String} postId 微博id
 * @param {String} commentPostId 要回复的评论ID
 * @param {String} text 微博内容
 * @param {Number} forward 是否作为一条新微博发布，1是，0否
 * @param {Number} headPictureType 评论显现头像类型, 默认是1，30大小的头像，2，50大小的头像
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    reply : function(id, cid, text, forward, hpt, fn, cfg){
		XwbRequest.postReq(XwbRequest.jsAPI('feedApi','comment_post'), {
            fid:id,
			comment_id : cid,
            text:text,
            forward : forward,
            type:hpt
           }, fn, cfg
        );
    },
/**
 * 回复游记评论
 * @param {String} postId 游记id
 * @param {String} commentPostId 要回复的评论ID
 * @param {String} text 游记评论内容
 * @param {Number} forward 是否作为一条新微博发布，1是，0否
 * @param {Number} headPictureType 评论显现头像类型, 默认是1，30大小的头像，2，50大小的头像
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
	youjiReply : function(id, cid, text, forward, hpt, fn, cfg){
		cfg = cfg?cfg:{};
        XwbRequest.postReq(XwbRequest.jsAPI('commentsApi','reply'), {
            id:id,
            cid:cid,
            text:text,
            forward : forward,
            type:hpt
           }, fn, cfg
        );
    },
/**
 * 关注某人，或批量关注用户
 * @param {String} user 关注用户，UID或微博名称
 * @param {Number} userDataType user参数类型，0为user id，1为微博名称
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    follow : function(user, dt, fn, cfg){
        XwbRequest.act('userApi','createFriendship', {id:user, type:dt}, fn, cfg);
    },

/**
 * @param {String} user 关注用户，UID或微博名称
 * @param {Number} userDataType user参数类型，0为user id，1为微博名称
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    unfollow : function(user, name, fn, cfg){
	    XwbRequest.postReq(XwbRequest.jsAPI('userApi','deleteFriendship'), {id:user, name:name}, fn, cfg);
        //XwbRequest.act('deleteFriendship', {id:user, name:name, is_follower:0}, fn, cfg);
    },
	
/**
 * 微博直播，通过景点ID返回微博
 * @param {Array} ids 景点id
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 */
	getWbBySpotId : function(ids, fn){
	    return this.q( this.jsAPI('weiboappApi','weiboMap'),{'spots_id':ids}, fn,{});
	},


/**
 * 分享经验-获取问题
 */
	getExpQuestion : function(type, sid, count, cursor, fn){
	    return this.postReq( this.jsAPI('experienceApi','share'),{'type':type, 'sid':sid, 'count':count, 'cursor':cursor}, fn,{});
	},

	
/**
 * 分享经验-编辑提交
 */
	expEditSubmit : function(id, text, fn){
	    return this.postReq( this.jsAPI('experienceApi','answerUpdate'),{'id':id, 'text':text}, fn,{});
	},
	
/**
 * 分享经验-不回答
 */
	expDelete : function(id, fn){
	    return this.q( this.jsAPI('experienceApi','delAsk'),{'id':id}, fn,{});
	},
	
/**
 * 分享经验-获取我的经验  count=10&cursor=0
 */
	getExp : function(cursor, fn){
	    return this.postReq( this.jsAPI('experience','getMyExp'),{'count':10, 'cursor':cursor}, fn,{});
	},
	
/**
 * 分享经验-问题回复
 */
	expAnswer : function(id, text, fn){
	    return this.postReq( this.jsAPI('experienceApi','answer'),{'qid':id, 'text':text}, fn,{});
	},

	
/**
 * 分享经验-问题编辑
 */
	expEdit : function(id, text, fn){
	    return this.postReq( this.jsAPI('experienceApi','answerUpdate'),{'qid':id, 'text':text}, fn,{});
	},

/**
 * 求助-获取问题
 */
	askQuestion : function(sid, count, fn){
	    return this.q( this.jsAPI('experienceApi','share'),{'b_type':2, 'sid':sid, 'count':count}, fn,{});
	},

/**
 * 求助-提交
 */
	submitQuestion : function(data, fn){
	    return this.postReq( this.jsAPI('experienceApi','ask'), data , fn,{});
	},

/**
 * 求助-感谢TA
 */
	expThanks : function(id, fn){
	    return this.postReq( this.jsAPI('experienceApi','thankYou'), {id : id} , fn,{});
	},
	
/**
 * 求助-获取问题答复
 */
	getReply : function(id, fn){
	    return this.postReq( this.jsAPI('experienceApi','getAns'), {id : id, count:200, cursor:0} , fn,{});
	},
	
/**
 * 经验分享-回答别人的问题
 */
	replyQuestion : function(data, fn){
	    return this.postReq( this.jsAPI('experienceApi','batchAnswer'), data , fn,{});
	},
	
/**
 * 移除粉丝
 * @param {String} user 关注用户，UID或微博名称
 * @param {Number} userDataType user参数类型，0为user id，1为微博名称
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
	removeFans : function(user, name, fn, cfg) {
		XwbRequest.act('deleteFriendship', {id:user, name:name, is_follower:1}, fn, cfg);
	},

/**
 * 收藏微博
 * @param {String} blogId 要收藏的微博ID
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    fav : function(id, fn, cfg){
        XwbRequest.act('createFavorite', {id:id}, fn, cfg);
    },
    
    delFav : function(id, fn, cfg){
        XwbRequest.act('deleteFavorite', {id:id}, fn, cfg);
    },

/**
 * 更改头像。
 * WARNING : 更改头像需要由form提交
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    updateHeadPic : function(image, fn, cfg){
        XwbRequest.act('updateProfileImage', {image:image}, fn, cfg);
    },
    
/**
 * 更新用户资料
 * @param {Object} data 用户资料（键值对）
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    setProfile : function(data, fn, cfg){
        XwbRequest.act('saveProfile', data, fn, cfg);
    },

/**
 * 获取未读数 包括消息，游记等
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    unread : function(fn, cfg){
		this.act('public','unread', {}, fn, cfg);
    },
	

/**
 * 后台获取未读数 包括消息，游记等
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    adminUnread : function(fn, cfg){
		this.postReq(this.mkUrl('admin/jsApi','majaMsgUnread'), {}, fn, cfg);
    },	
    
/**
 * 清零未读消息数目
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    clearUnread : function(fn, cfg){
        this.act('public','resetUnread', {}, fn, cfg);
    },
    
/**
 * 获取指定的微博评论列表
 * @param {String} id 微博ID
 * @param {Number} page 评论的页码
 * @param {Number} type 列表类型, 默认是1，微博列表的某条微博评论列表，2单条微博的详细评论列表
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    getComments : function(id, page, type, fn, cfg){
        XwbRequest.act('spotsApi','weiboComments', {fid:id, cursor:page, type:type||1}, fn, cfg);
    },
/**
 * 获取指定的微博评论列表
 * @param {String} id 游记ID
 * @param {Number} page 评论的页码
 * @param {Number} type 列表类型, 默认是1，微博列表的某条微博评论列表，2单条微博的详细评论列表
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
	getYoujiComments: function(id, page, type, fn, cfg){
		cfg = cfg?cfg:{};
		cfg.url = XwbRequest.jsAPI('commentsApi','getComments');
		XwbRequest.act('commentsApi','getComments', {id:id, page:page, type:type||1}, fn, cfg)
    },

/**
 * 发短消息
 * @param {String} targetUserId 用户帐号ID，与用户微博名称两者给出其一即可
 * @param {Number} userType 指明第一个参数的类型，用户ID时值为0, 用户微博名称时为1，默认为0
 * @param {String} targetWeiBoName 用户微博名称与帐号ID两者给出其一即可
 * @param {String} text 短消息内容
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    msg : function(uid, userType, text, fn, cfg){
		XwbRequest.postReq(XwbRequest.jsAPI('userApi','sendDirectMessage'), {id : userType?'':uid, name: userType?uid:'', text:text}, fn, cfg);
    },

/**
 * 删除短消息
 * @param {String} msgId 短消息ID
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    delMsg : function(id, fn, cfg){
        this.postReq(this.jsAPI('messageApi','del_pms'), {id:id}, fn, cfg);
    },
	
/**
 * 删除短消息整个对话
 * @param {String} id 用户id
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    delDia : function(uid, fn, cfg){
        this.postReq(this.jsAPI('messageApi','del_dialogue'), {uid:uid}, fn, cfg);
    },
	
	
/**
 * 查看某人是否是目标用户的粉丝
 * @param {String} user 目标用户
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Number} targetAccountType 目标帐号类型，如果参数传入的是用户ID，为0,如果参数为用户微博名称则为1
 * @param {String} src 源用户(不指定，就使用当前登录用户)
 * @param {Number} sourceAccountType 源帐号类型，如果参数传入的是用户ID，为0,如果参数为用户微博名称则为1
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    followed : function(user, fn, userType, src, srcType, cfg){
        var data = {};
        if( userType )
            data.t_name = user;
        else data.t_id  = user;
        if(src){
            if(srcType)
                data.s_name = src;
            else data.s_id  = src;
        }
        XwbRequest.act('friendShip', data, fn, cfg);
    },
    
/**
 *  个人设置
 * @param {String} type 设置类型，默认是’autoshow’新微博显示方式，’tipshow’未读数显示方式
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    setting : function(type, fn, cfg){
        XwbRequest.act('setting',{type:type}, fn, cfg);
    },

/**
 *  屏蔽单条微博
 * @param {String} weiboId 微博ID
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    shieldBlog : function(wbId, fn, cfg){
        XwbRequest.postReq(XwbRequest.mkUrl('show', 'disabled'), {id:wbId}, fn, cfg);
    },
/**
 *  举报单条微博
 * @param {String} weiboId 微博ID
 * @param {String} content
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    reportSpam : function(wbId, content, fn, cfg){
        XwbRequest.postReq(XwbRequest.mkUrl('show', 'reportSpam'), {cid:wbId, content:content}, fn, cfg);
    },

/**
 *  增加标签
 * @param {String} tagList 逗号分隔
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    createTags : function(tagList, fn, cfg){
        XwbRequest.act('createTags', {tagName:tagList}, fn, cfg);
    },

/**
 * 删除标签
 */
    delTag : function(tagId, fn, cfg){
        XwbRequest.act('deleteTags', {tag_id:tagId}, fn, cfg);
    },
    
    updateShowProfile : function(data, fn, cfg){
        XwbRequest.act('saveShow', data, fn, cfg);
    },
    
    updateNoticeProfile : function(data, fn, cfg){
        XwbRequest.act('saveNotice', data, fn, cfg);
    },
/**
 * 发送提醒。
 * @param {String} userId, (sina_id), 0表示本站所有用户
 * @param {String} title
 * @param {String} content
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    notice : function(uid, title, content, time, fn, cfg){
        XwbRequest.postReq(XwbRequest.apiUrl('action', 'sendNotice'), {available_time:time,uid:uid,title:title,content:content}, fn, cfg);
    },
    
/**
 * 设置皮肤
 * @param {Object} 皮肤参数（如果只有skin_id，表示使用皮肤列表，否则就是自定义皮肤）
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    saveSkin : function(data, fn, cfg){
        // url, data, success, cfg
        XwbRequest.postReq(XwbRequest.mkUrl('setting', 'setSkin'), data, fn, cfg);
    },
    
/**
 * 设置皮肤(后台设置)
 * @param {Object} 皮肤参数（如果只有skin_id，表示使用皮肤列表，否则就是自定义皮肤）
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    saveMgrSkin : function(data, fn, cfg){
        // url, data, success, cfg
        XwbRequest.postReq(XwbRequest.mkUrl('mgr/setting', 'setSkin'), data, fn, cfg);
    },
    
/**
 * 获取多条微博转发数，评论数等信息
 * @param {String} weiboIds 微博ID列表，由逗号分隔
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    counts : function(ids, fn, cfg){
        XwbRequest.act('getCounts', {ids:ids}, fn, cfg);
    },

/**
 * 添加用户黑名单
 * @param {String} id 用户ID
 * @param {String} name 用户昵称 
 * 参数二选一即，如只知道昵称 (null, 'billgate');
 */
	blacklistAdd : function(id, name, fn, cfg) {
		XwbRequest.act('createBlocks', {id:id,name:name}, fn, cfg);
	},

	blacklistDel : function(id, name, fn, cfg) {
		XwbRequest.act('deleteBlocks', {id:id,name:name}, fn, cfg);
	},
	

/**
 * 获取省份城市列表
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 */
	getProvinces : function(fn) {
		XwbRequest.act('getProvinces', null, fn);
	},

/**
 * 用户反馈
 * @param {Object} data 微博ID列表，由逗号分隔
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
	feedback : function(data, fn, cfg){
	    this.postReq( this.mkUrl('feedback','save'), data, fn, cfg );
	},

/**
 * @class Xwb.request
 */
/**
 * 解析短链接,ID可为多个，逗号分隔。<br/>
 * 一般情况下，不必直接调用本方法，利用{@link Xwb.ax.Shortlink}类提供各种解析短链的方法，包括文本，DOM上的短链接，可解决大部份问题。
 * @param {String} shortLinkId
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
    sinaurl : function(id, fn){
        XwbRequest.act('sinaurl', {id:id}, fn);
    },
    
    search  : function(key, fn, wb) {
        //var params = {k: key, t:'fm'};
		var params = {k: key};
        
        if (wb) {
            params.wb = 1;
        }

        return XwbRequest.q(XwbRequest.jsAPI('spotsApi','search'), params, fn, {prefix : api_spots, method : 'GET'});
    },
	
	
	searchTotal : function(key, fn, cfg){
		return XwbRequest.q(XwbRequest.jsAPI('public','search'), {q: key}, fn, {method : 'GET'});
	},
	
	
     /**
    //是否喜欢某条微博
    /**
    * type 喜欢的类型 1：微游记 0：微博
    like : function(sid, wid, islike,type, fn) {
        islike = islike ? 1: 0;
        return XwbRequest.act('likeSpots', {wb_id: wid, is_like : islike , spots_id: sid , type : type}, fn , {prefix : api_spots, method : 'GET'});
    }, 
	*/
	    //是否喜欢某条微博
    /**
    * type 喜欢的类型 1：微游记 0：微博
    */
    like : function(url, param, wid, islike, fn) {
        islike = islike ? 1: 0;
        return XwbRequest.postReq(url || XwbRequest.jsAPI('feedApi','like_set'),  param || {fid: wid, like : islike}, fn , {prefix : api_spots, method : 'GET'});
    },
    //是否喜欢某条微博
    /**
    * type 喜欢的类型 1：微游记 0：微博
    */
    youjiLike : function(url, param, wid, islike, fn) {
        islike = islike ? 1: 0;
        return XwbRequest.postReq(url || XwbRequest.jsAPI('youjiApi','like'), param || {youji_id: wid, is_like : islike}, fn , {prefix : api_spots, method : 'GET'});
    },
    //景点附近经常出没的人
    spotUsers : function(sid, fn) {
        return XwbRequest.act('getUserFromSpots', {spots_id: sid}, fn, {prefix : api_spots, method : 'GET'});
    },
    
    //设置景点状态：-1 清除 1：想去 2：去过
    setStateSpots : function(sid, state, fn) {
        return XwbRequest.act('setStateSpots', {spots_id: sid, state: state}, fn, {prefix : api_spots, method : 'GET'});
    }, 
    
    //查询我的景点
    mySpots : function(fn) {
        return XwbRequest.act('getMySpots', null, fn, {prefix : api_spots, method : 'GET'});
    },
    
    //附近的景点
    nearSpots : function(sid, fn) {
        return XwbRequest.act('spotsApi','getNearbySpots', {spots_id: sid, count : 8}, fn, { method : 'GET'});
    },
    
    //管理员推荐微博
    recommend : function(data, recm, fn) {
        return XwbRequest.act('setSpotsWbAsRec', $.extend({is_recom: recm}, data), fn, {prefix : api_spots});
    },
    
    //管理员删除微博
    admDel : function(wbid, spid, fn){
        return XwbRequest.act('delWb', {spots_id: spid, wb_id: wbid}, fn, {prefix : api_spots});
    },
	
	//提问
	ask : function(data, fn, cfg){
		this.postReq( this.jsAPI('consultApi','ask'), data, fn, cfg );
	},
	
	//答问
	doAsk : function(data, fn, cfg){
		this.postReq( this.jsAPI('consultApi','answer'), data, fn, cfg );
	},
	
	//有用回答
	ansUseful : function(data, fn, cfg){
		this.postReq( this.jsAPI('consultApi','ansUseful'), data, fn, cfg );
	},
	
	//无用回答
	ansNouse : function(data, fn, cfg){
		this.postReq( this.jsAPI('consultApi','ansNouse'), data, fn, cfg );
	},
	
	//感谢
	thankYou : function(data, fn, cfg){
		this.postReq( this.jsAPI('consultApi','thankYou'), data, fn, cfg );
	},
	
	//找关注的人
	selectUser : function(url,data, fn, cfg){
		return this.postReq( url, data, fn, cfg );
	},
	
	//获取足迹 分页
	getFootMark : function(data, fn, cfg){
		return this.postReq( this.jsAPI('spaceApi','fmList'), data, fn, cfg );
	},
	
	//移除足迹
	delMark : function(data, fn, cfg){
		return this.postReq( this.jsAPI('footmarkApi','removeFm'), data, fn, cfg );
	},
	
	//我的游记
	getYoujis : function(data, fn, cfg){
		return this.postReq( this.jsAPI('spaceApi','youji_list'), data, fn, cfg );
	},
	
	//判断用户是否第一次登录显示提醒
	getRemindState : function(data, fn, cfg){
		return this.postReq( this.jsAPI('public','getRemindState'), data, fn, cfg );
	},

	//取消初次登录用户提醒
	closeRemind : function(data, fn, cfg){
		return this.postReq( this.jsAPI('public','closeRemind'), data, fn, cfg );
	},
	//发短消息（有短消息页）
	sendMessage : function(uid, userType, text, fn, cfg){
		this.postReq(this.jsAPI('messageApi','post'), {uid : userType?'':uid, name: userType?uid:'', text:text}, fn, cfg);
	},
	
	//我想去|我去过{sid:id, state:1} ; 1：想去 2：去过
	setFm : function(data, fn, cfg){
		return this.act( 'footmarkApi','setFm', data, fn, cfg );
	},
	
	//批量设置我想去|我去过  不过只能存在一种 格式{p:'id:static,id2:static'} state: -1 删除 1：想去 2：去过
	batchSetFm : function(data, fn, cfg){
		return this.act( 'journeyApi','batchSetFm', data, fn, cfg );
	},
	
	//获取表情
	getEmotions : function( fn, cfg){
		return this.postReq( this.jsAPI('public','getEmotions'), {}, fn, cfg );
	},
	
	//获取分享到微博时的内容
	getShareString : function(type, id, fn, cfg){
		return this.postReq( this.jsAPI('public','getShareString'), {type:type, id:id}, fn, cfg );
	},
	
	//分享到微博 msg:内容，　target:分享到的微博｛target=qq,sina,renren｝　
	doShare : function(msg, target, pic, title, url, type, id, fn, cfg){
		return this.postReq( this.jsAPI('public','doShare'), {msg : msg, target:target, pic:pic, title:title, url:url, type:type, id:id}, fn, cfg );
	},
	
	//获取当前登录用户绑定数据
	bindLst : function(uid, fn, cfg){
		return this.postReq( this.jsAPI('public','bindLst'), {uid : uid}, fn, cfg );
	},
	
	//删除消息
	delNotice : function(wid, fn, cfg){
		return this.postReq( this.jsAPI('messageApi','del'), {id : wid}, fn, cfg );
	}, 

	//用户名片
	getUserInfo : function(uid, fn, cfg){
		return this.q( this.jsAPI('accountApi','getUserInfo'), {uid : uid}, fn, cfg );
	},
	//用户勋章 
	getMedalInfo : function(uid, fn, cfg){
		return this.q( this.jsAPI('accountApi','getMedalInfo'), {uid : uid}, fn, cfg );
	},
	
	//礼品专题,获取列表
	getSpecialComment : function(pid, page, n1 ,  fn, cfg){
		return this.postReq( this.jsAPI('guestbookApi','getList'), {pid : pid, page: page}, fn, cfg );		
	},
	
	specialComment : function(pid, content, n1 ,n2, fn, cfg){
		var len = arguments.length;
		if(len == 6){
			var param = {pid : arguments[0], content:  arguments[1]};
			fn = arguments[4];
			cfg = arguments[5];
		}else{
			var param = {pid : arguments[0], content:  arguments[2]};
			fn = arguments[5];
			cfg = arguments[6];
		}
			
		return this.postReq( this.jsAPI('guestbookApi','post'), param, fn, cfg );				
	},
    
    //获取自游记comment
    getZyjComment : function(id, page, type, fn) {
        page = page || 1;
        var count = 10;
        return XwbRequest.getReq(XwbRequest.url.zyj('getComments'), {
            id : id,
            page : page,
            count : count
        }, fn);
    },
    
    //发送自游记comment
    zyjComment : function(id, text, type, p, fn){
        return XwbRequest.postReq(XwbRequest.url.zyj('comment'), {
            id : id,
            text : text
        }, fn);
    },
    
    //删除接口 comment_destroy
    delZyjComment : function(id, type, fn) {
        return XwbRequest.postReq(XwbRequest.url.zyj('comment_destroy'), {
            id : id
        }, fn);
    },
    
    //删除自游记的comment
    zyiDelComment : function(cid, fn) {
        return XwbRequest.postReq(XwbRequest.url.zyi('comment_destroy'), {
            id : cid
        }, fn);
    },
	
	
    //获取对角矩阵下的景点接口
    /**
    * sw 西南角，
    * ne 东北角
    * num 获取n条数据
    * top 是否取热站景点 true|false
    * page 页码>=1,必须设置num后才起作用
    * fn 回调
    */
    getSpotsByDM : function(sw, ne, num, top, page, fn) {
        return this.postReq(this.jsAPI('spotsApi','getSpotsByDM'), {
            sw: sw,
            ne: ne,
            num: num||10,
            topic : top || 1,
            page : page || 1
        }, fn, {prefix : api_spots, method: 'GET'});
    },

	//获取某个坐标附近的景点
    //rs:半径 单位（km）
	getSpotsNearPoint : function(p, rs, num, fn){
		return this.postReq(this.jsAPI('spotsApi','getSpotsByPivot'), {pivot: p, radius: rs, num: num || 5}, fn , {prefix: api_spots, method: 'GET'});
	},
	
	//游记上传图片
	//pic:  上传图片地址
    youjiUpLoadImg : function(pic,fn){
		return XwbRequest.postReq(XwbRequest.jsAPI('youjiApi','uploadPhoto'),{pic_url:pic},fn,{});
	},
	
	//发游记
	parseYouji : function(data, fn, cfg){
		return this.act('youjiApi','parseYouji', data ,fn, cfg);		
	},
	
	//获取好友开通服务列表
	getFriendService :function(fn){
		return XwbRequest.q(XwbRequest.jsAPI('accountApi','getFriendService'),{},fn,{});
	},
	//获取微博开通服务列表
	getWbService :function(fn){
		return XwbRequest.q(XwbRequest.jsAPI('youjiApi','getWbTimelineService'),{},fn,{});
	},
	//获取微博列表
	//type:类型
	getwbTimeline :function(type,max_id,onceCount,page, maxtime ,fn){
		return XwbRequest.q(XwbRequest.jsAPI('youjiApi','wbTimeline'),{type:type,max_id:max_id,count:onceCount,page:page, maxtime:maxtime},fn,{});
	},
	
	//获取好友列表
	//type: 类型
	getFriend :function(type,page,pageCount,fn){
		return XwbRequest.q(XwbRequest.jsAPI('accountApi','getFriends'),{type:type,count:pageCount,page:page},fn,{});
	},
	
	//获取某相册图片列表
	//type:  类型
	//album_id :相册ID
     getPhotosList: function(type,album_id,fn){
		return XwbRequest.postReq(XwbRequest.jsAPI('youjiApi','getPhotos'),{type:type,album_id:album_id},fn,{});
	},
	
    //获取某相册图片列表
	//type:  类型
	//album_id :相册ID
     getPhotosListPage: function(page, count, type,album_id,fn){
		return XwbRequest.postReq(XwbRequest.jsAPI('youjiApi','getPhotos'),{page:page, count:count, type:type,album_id:album_id},fn,{});
	},
	
    //分享游记
	shareYouji : function(youji_id,pic,fn){
		return XwbRequest.postReq(XwbRequest.jsAPI('youjiApi','shareYouji'),{youji_id:youji_id,pic:pic},fn,{});
	},
    
    
    //分享游记 第二个接口比shareyouji不一样的是 分享的图片使用base64编码提交, 并加上提到的用户的字段
    //data {object}
    // youji_id pic_bin users_at(json array) text
    shareYouji2 : function(data, fn) {
        return XwbRequest.postReq(XwbRequest.jsAPI('youjiApi','shareYouji'), data, fn);
    },
	
	//设置setRemind
	setRemind: function(type,value,fn){
		return XwbRequest.postReq(XwbRequest.jsAPI('public','setUserCfg'),{type:type,value:value},fn,{});
	},
    
    //setRemind 别名
    saveCfg : function() {
        this.setRemind.apply(this, arguments);
    },
    
	//游记获取草稿
	loadCraft : function(fn){
		return XwbRequest.postReq(XwbRequest.jsAPI('youjiApi','getYoujiDraft'),{},fn,{});
	},
	clearCraft : function(fn){
		return XwbRequest.postReq(XwbRequest.jsAPI('youjiApi','clearCraft'),{},fn,{});
	},
	//游记举报
	YReport : function(id,type,content,fn){
		return XwbRequest.postReq(XwbRequest.jsAPI('youjiApi','report'),{id:id,content:content,type:type},fn,{});
	},
	//评论举报
	CReport : function(id,type,content,fn){
		return XwbRequest.postReq(XwbRequest.jsAPI('commentsApi','report'),{id:id,content:content,type:type},fn,{});
	},
	//问题举报
	QReport : function(id,type,content,fn){
		return XwbRequest.postReq(XwbRequest.jsAPI('public','report'),{id:id,content:content,type:type,item_type:5},fn,{});
	},
	//问题答案举报
	AReport : function(id,type,content,fn){
		return XwbRequest.postReq(XwbRequest.jsAPI('public','report'),{id:id,content:content,type:type,item_type:6},fn,{});
	},

    
    //比一比足迹数据
    compare : function(uid, fn, cfg) {
		cfg = cfg || {};

        return XwbRequest.act('compare', {sina_uid : uid}, fn , $.extend({url: '/index.php?m=app.compare', method : 'GET'}, cfg));
    },
	
	//第三方帐号解绑
	unBind3Part : function(type, fn){
		return XwbRequest.postReq(XwbRequest.jsAPI('settingApi','unbind'),{'type': type},fn,{});
	},
	
	//邮箱绑定
	ckEmail : function(email, fn){
	    return XwbRequest.postReq(XwbRequest.jsAPI('settingApi','setEmail'),{'email': email},fn,{});
	},
	
	//去哪玩页，获取省份数据
	getProvince : function(fn){
	    XwbRequest.postReq( XwbRequest.jsAPI('public','getProvince'),{}, fn,{});
	},
	
	//景点攻略编辑纠错
	editSpotsGuide : function( param, fn ){
	    XwbRequest.postReq( XwbRequest.jsAPI('spotsApi','submitCorrect'), param , fn, {});
	},
	
	//目的地详细页，获取最新最热游记
	getHotOrNewYouji : function( param, fn ){
	    XwbRequest.postReq( XwbRequest.jsAPI('spotsApi','youjiListInDetailDest'), param , fn, {});
	},
	
	//首页取最热数据
	getHotList : function( param, fn ){
	    XwbRequest.postReq( XwbRequest.jsAPI('youjiApi','hotList'), param , fn, {});
	},
	//首页取最新数据
	getNewList : function( param, fn ){
	    XwbRequest.postReq( XwbRequest.jsAPI('youjiApi','latestList'), param , fn, {});
	},
	
	//获取发表游记的提示
	getRemindStatus : function(param, fn){
		XwbRequest.q( XwbRequest.jsAPI('public','getRemindStatus'), param , fn, {});
	},
    
	//反馈
	feedBack : function(param, fn){
		XwbRequest.q( XwbRequest.jsAPI('public','doSuggestion'), param , fn, {});
	},
	
	//获取中奖结果
	getLotteryResult : function(fn){
		XwbRequest.q( XwbRequest.jsAPI('events/invite','getLotteryResult'), {} , fn, {});
	},
	
	//保存中奖者信息
	saveWinnerInfo : function( param, fn ){
	    XwbRequest.postReq( XwbRequest.jsAPI('events/invite','saveWinnerInfo'), param , fn, {});
	},
	
	//查看谁正在抽奖
	getVisitor : function( fn ){
	    XwbRequest.postReq( XwbRequest.jsAPI('events/invite','visitor'), {} , fn, {});
	},
	
	//查看热门景点
	getHotSpots : function( fn ){
	    XwbRequest.postReq( XwbRequest.jsAPI('events/invite','hot_spots'), {} , fn, {});
	},
    
    //查询绑定的社区好友
    //type : sina|qq|renren 
    searchFriends : function(type, kw, count, fn, opt) {
    //searchFriends : function(kw, fn, opt) {
        //opt = opt || {};
        //var params = {q:kw,type: opt.type, count: opt.count||10, page:1};
        var params = {q: kw, type: type, count: count||10, page:1};
        
        return XwbRequest.getReq( XwbRequest.jsAPI('accountApi','searchFriends'), params, fn );
    },
	
	//查询自游网用户
	searchLocalFriends : function(q, fn){
		return XwbRequest.postReq( XwbRequest.jsAPI('userApi','searchFriends'), {q: q} , fn);
	},

	//获取第三方相册
	getAlbumsService : function( fn ){ 
	    return XwbRequest.getReq( XwbRequest.jsAPI('accountApi','getAlbumsService'), {}, fn );
	},
	
	//获取第三方相册列表
	getAlbums : function( type, uid, fn ){ 
		XwbRequest.q( XwbRequest.jsAPI('youjiApi','getAlbums'), {type: type,uid: uid} , fn, {});
	},
	
	//增加印象
	addImpression : function(sid, text, fn){
		this.postReq(this.jsAPI('impressionApi','add'), {sid: sid, text: text}, fn, {} );		
	},
	
	//取景点微博
	getFeedTimeline : function(p, fn){
		this.postReq(this.jsAPI('feedApi','getFeedTimeline'), {spots_id:p.spots_id,max_id:p.max_id,count:p.count}, fn, {} );
	},
	
	//取微博列表
	getWeiboLists : function(p, fn){
		this.q(this.jsAPI('weiboappApi','weiboList'), {page: p.page}, fn, {} );		
	},
	
	//点评
	pointComment : function(sid, text, st, fn){
		this.act('tipsApi','add', {id: sid, text: text, st:st}, fn, {} );		
	},
	
	//游记home滚动加载接口
	getHomeYouji : function(p, fn){
		this.q(this.jsAPI('youjiApi','getHomeYouji'), p, fn, {} );
	},
	
	//获取点评列表
	getPointComments : function(sid, page, type, tid, fn){
		//this.q(this.jsAPI('tipsApi','listData'), {id: sid, sort: type, tid:tid, cursor: page}, fn, {method : 'GET'} );	
		this.act('tipsApi','listData', {id: sid, type: type, tid:tid, cursor: page}, fn,{method : 'GET'});		
	},
	//赞成\反对
	setUseful : function(sid, v, fn){
		this.postReq(this.jsAPI('tipsApi','setUseful'), {id: sid, v: v}, fn, {} );		
	},
	//某点评回复列表
	getPointReplyList : function(sid, cid, cursor, fn){
		this.q(this.jsAPI('tipsApi','listReply'), {id: sid, tid: cid, cursor: cursor}, fn, {} );	
	},
	
	//回复点评
	pointReply : function(sid, cid, rid, text, fn){
		this.postReq(this.jsAPI('tipsApi','reply'), {id: sid, tid: cid, rid:rid, text: text}, fn, {} );	
	},
	
	//删除点评
	delPointReply : function(id, cid, fn){
		this.postReq(this.jsAPI('tipsApi','del'), {id: id, tid: cid}, fn, {} );	
	},
	
	/*
	 * 头图推荐
	 * */
	getCoverList : function(fn){
		　this.q(this.jsAPI('journeyApi','coverList'), {}, fn, {} );	
	},
	 
	 /*
	 * 保存头图
	 * */
	saveCoverList : function(imgId, y, fn){
		　this.postReq(this.jsAPI('journeyApi','saveCover'), {img : imgId, y:y}, fn, {} );	
	},
	
	
	
	getHomeYouji : function(p, fn){
		this.q(this.jsAPI('youjiApi','getHomeYouji'), p, fn, {} );
	},
	
	//查询图片是否已加入到我的印象	
	jsApiCall : function( module, action , queryStr, fn, method,cfg){
		var url = this.jsAPI(module,action);
		method = method || 'GET';
		if( method.toLocaleUpperCase() === 'GET')
			this.q( url, queryStr, fn, cfg );
		else 
			this.postReq( url, queryStr, fn, cfg);	
    },
	
	//取子景点
	getSpotsSub : function(id, page, fn){
		this.q(this.jsAPI('spotsApi','subitems'), {id:id, page : page}, fn, {} );
	},
	
	//根据点评Ids获取点评状态
	getStateByTipsIds : function(ids, fn){
		this.postReq(this.jsAPI('messageApi','feedAjax'), {tips:ids}, fn, {} );
	},
	//根据贴子Ids获取点评数
	getTipsCount : function(ties, fn){
		this.postReq(this.jsAPI('messageApi','feedAjax'), {ties:ties}, fn, {} );
	},
    
    /**
    * 代理flash的服务请求
    * name 封装于jsApi/flash.name
    * data {key : value} $_GET['a']
    * cbScopeAname  flashId.callbackName
    * cfg
    *   cfg.method: [POST/GET]
    */
    flashReq : function(name, data, cbScopeAname, cfg) {
        this.act('flash', name, data, function(e){
            if (!window.swfobject) {
                throw new Error('swfobject not exists');
            }
            var cb = cbScopeAname.split('.', 2),
                id = cb[0],
                fnName = cb[1];
            var flash = swfobject.getObjectById(id);
            try{
                flash[fnName](e.isOk(), e.getData(), e.getCode(), e.getMsg());
            }catch(e) {
                if (__debug) console.log('call flash callback method failed. id: %s, method:%s,data:%o', id, fnName, e.getRaw());
            }
        }, cfg);
    },
    
    /**
    * 获取小组列表
    */
    groupList : function(fn){
        return this.getReq(this.jsAPI('groupApi', 'get_list'), null, fn);
    },
    
    /**
    * 保存小组设置信息
    * @param data {desc : 'test'}
    */
    saveGroupInfo : function(group_id, data, fn) {
        data = data || {};
        data.gid = group_id;
        return this.postReq(this.jsAPI('groupApi', 'admin_updateGroupInfo'), data, fn);
    },
	
	/**
	 * 明信片喜欢
	 */
	postCardLike : function(pid, fn){
		return this.postReq(this.jsAPI('postcardApi', 'like'), {pid : pid}, fn);
	},
	/**
	 * 明信片取消喜欢
	 */
	postCardunLike : function(pid, fn){
		return this.postReq(this.jsAPI('postcardApi', 'unlike'), {pid : pid}, fn);
	},
	
	/**
	 * 明信片删除(type: 1我的明信片，type :2收到的明信片)
	 */
	postCardDel : function(pid, type, fn){
		return this.postReq(this.jsAPI('postcardApi', 'del'), {pid : pid ,type:type}, fn);
	},
	
	
	/**
	 * 明信片评论列表
	 */
	getPostCardList : function(pid, page, count, fn){
		return this.act('postcardApi', 'getComments', {pid : pid, page:page, count:''}, fn);
	},
	
	//分享明信片
	postcardShare : function(pid, text, to_users, fn){
		return this.act('postcardApi', 'share', {pid : pid, text:text, to_users:to_users}, fn);
	},
	
	
	//输入字符过滤
	filterKeyword : function(text, fn){
		return this.act('keywordApi', 'filterKeyword',  {content:text}, fn);
	},
	
	/**
	 * 评论明信片
	 * @param {String} postId 明信片pid
	 * @param {String} text 明信片评论内容
	 * @param {Number} forward 是否作为一条新微博发布，1是，0否
	 * @param {Number} headPictureType 评论显现头像类型, 默认是1，30大小的头像，2，50大小的头像
	 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
	 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
	 */
    postCardComment : function(pid, text, forward, hpt, fn, cfg){
		this.act('postcardApi', 'comment', {
            pid:pid,
            text:text,
            forward : forward,
            type:hpt
           }, fn, cfg
        );
    },
	
	/**
 * 回复明信片评论
 * @param {String} postId 明信片pid
 * @param {String} commentPostId 要回复的评论ID
 * @param {String} text 明信片评论内容
 * @param {Number} forward 是否作为一条新微博发布，1是，0否
 * @param {Number} headPictureType 评论显现头像类型, 默认是1，30大小的头像，2，50大小的头像
 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
 */
	postCardReply : function(pid, id, text, forward, hpt, fn, cfg){
		cfg = cfg?cfg:{};
        XwbRequest.postReq(XwbRequest.jsAPI('postcardApi','reply'), {
            id:pid,
            id:id,
            text:text,
            forward : forward,
            type:hpt
           }, fn, cfg
        );
    },
	
	/*
	 * 删除明信片评论
	 * */
	delPostCardCmt : function(id, d, fn){
		this.act('postcardApi','comment_destroy', {id:id}, fn,  {});
	},
	
	//明信片选模板
	getTplList : function(param, fn){
		return this.postReq(this.jsAPI('postcardApi','getTplList'), param, fn);
	},
	
	//明信片贴邮票
	getTpcList : function(param, fn){
		return this.postReq(this.jsAPI('postcardApi','getMaterialList'), param, fn);
	},
	
	//搜索邮戳
	postCardYoSearch : function(param, fn){
		return this.postReq(this.jsAPI('postcardApi','search'), param, fn);
	},
    
    /**
    * 将某（些）用户加到黑名单列表
    * @param group_id int 群组ID
    * @param uid string|array 用户ID，支持多个
    * @callback fn
    * @param type [int] 参数类型 1：用户ID，2:用户昵称 默认 1
    */
    memberAddBlack : function(group_id, uid, fn, type){
        var 
            idParam = $.isArray(uid) ? uid.join(','): uid;
            params = {gid: group_id};
        type = type || 1;
        params[type == 1 ? 'uid' : 'nickname'] = idParam;
        
        return this.postReq(this.jsAPI('groupApi','admin_memberAddBlack'), params, fn);
    },
    
    /**
    * 剔除群组成员
    */
    memberDel : function(group_id, uid, fn) {
        return this.postReq(this.jsAPI('groupApi', 'admin_memberDel'), {gid: group_id, member_id : $.isArray(uid) ? uid.join(','): uid}, fn);
    },
    
    /**
    * 解除黑名单 
    */
    memberDelBlack : function(group_id, uid, fn) {
        //groupApi.admin_memberDelBlack
        return this.postReq(this.jsAPI('groupApi', 'admin_memberDelBlack'), {gid: group_id, uid : $.isArray(uid) ? uid.join(','): uid}, fn);
    },
	
	/**
	 * 获取指定话题评论列表
	 * @param {String} id 帖子ID
	 * @param {Number} page 游标
	 * @param {Number} find_cid 要回复的评论的ID
	 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
	 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
	 */
	getTopicComments: function(id, page, find_cid, fn, cfg){
		XwbRequest.act('groupApi','topicComment_list', {id: id ,page: page, find_cid: find_cid}, fn,{method:'GET'})
    },
	
	/**
	 * 评论话题
	 * @param {String} id id
	 * @param {String} text 评论内容
	 * @param {Number} forward 是否作为一条新微博发布，1是，0否
	 * @param {Number} headPictureType 评论显现头像类型, 默认是1，30大小的头像，2，50大小的头像
	 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
	 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
	 */
    topicComment : function(id, text, forward, hpt, fn, cfg){
		cfg = cfg || {};
		this.act('groupApi', 'topicComment_send', {
				id		:	id,
				text	:	text
           }, fn, cfg);
    },
	/**
	 * 回复帖子评论
	 * @param {String} postId 游记id
	 * @param {String} commentPostId 要回复的评论ID
	 * @param {String} text 游记评论内容
	 * @param {Number} forward 是否作为一条新微博发布，1是，0否
	 * @param {Number} headPictureType 评论显现头像类型, 默认是1，30大小的头像，2，50大小的头像
	 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
	 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
	 */
	topicReply : function(id, cid, text, forward, hpt, fn, cfg){
		cfg = cfg?cfg:{};
        XwbRequest.postReq(XwbRequest.jsAPI('groupApi','topicComment_reply'), {
				id		: cid,
				text	: text
           }, fn, cfg);
    },
	/**
	 * @param {String} id 本地评论id
	 * @param {String} rid 评论微博id  //rid未使用,只是为兼容 wbcomment 的接口保留的参数
	 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
	 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
	 */
    topicDelComment : function(id , rid , fn, cfg){
        XwbRequest.act('groupApi','topicComment_del', {id:id}, fn, cfg);
    },
	//删除帖子
	topicDel : function( tid, fn ){
		this.jsApiCall( 'groupApi','topic_delete',{id: tid},fn,'POST');
	},
	
	//帖子举报、帖子评论举报 参数说明请看 wiki: http://wiki.dev/index.php/VYJ-API::/group/report/send
	topicReport : function( type_id, topicType, fn){
		XwbRequest.act('groupApi','report_send', { type_id : type_id, type: topicType }, fn);
	},
	
	
	/**
	 * 获取印象评论列表
	 * @param {String} img_id
	 * @param {Number} page 游标
	 * @param {Number} type 未使用
	 * @param {Function} callback 成功后回调方法，参数为 callback(Xwb.ax.ResponseDefinition definition)
	 * @param {Xwb.ax.RequestConfig} [config] 可选，请求配置信息
	 */
	getImageComments: function(img_id, page, type, fn, cfg){
		XwbRequest.act('commentsApi','getImageComments', {id: img_id ,page: page, count: 10}, fn,{method:'POST'})
    },
	

	//旅途
	//添加旅途
	addJourney : function(year, month, story, img, postcard_id, spot_id, type, spot_Name, status, fn, cfg){
		this.postReq(this.jsAPI('journeyApi','journeyAdd'), {
		 year:year
		, month:month
		, story:story
		, img:img
		, postcard_id :postcard_id
		, spot_id: spot_id
		, type : type
		, status : status
		, spot_name:spot_Name}, fn, cfg);
	},
	
	//更新旅途
	journeyUpdate : function(id, status, year, month, story, img, postcard_id, spot_id, spot_Name, fn, cfg){
		this.postReq(this.jsAPI('journeyApi','journeyUpdate'), {
		 id : id	
		, year:year
		, month:month
		, story:story
		, status : status
		, img:img
		, postcard_id :postcard_id
		, spot_id: spot_id
		, spot_name:spot_Name}, fn, cfg);
	},
	
	//删除旅途
	journeyDel : function(id, sid, fn){
		var param = {};
		if(id) param.id = id;
		if(sid) param.sid = sid;
		XwbRequest.act('journeyApi','journeyDel', param, fn);
	},
	
	/**
	 * 获取用户景点的图片
	 */
	journeyPhoto : function(page, spot_id, spot_name, count, fn, cfg){
		this.q(this.jsAPI('journeyApi','journeyPhoto'), {
		 page:page
		, spot_id:spot_id
		, spot_name:spot_name
		, count:count}, fn, cfg);
	},
	
	//旅途地图－想去
	addWantTo : function(sid, fn, cfg){
		this.q(this.jsAPI('journeyApi','addWantTo'), {
		 sid:sid
		}, fn, cfg);
	},
	
	//删除
	delWantTo : function(sid, fn, cfg){
		XwbRequest.act('journeyApi','delWantTo', {
		 sid:sid
		}, fn, cfg);
	},
	
	//设置用户签名
	setIntro : function(introduction, fn){
		this.postReq(this.jsAPI('settingApi','setIntro'), {
			introduction : introduction
		}, fn)
	},
	
	//专题制作后台
	
	//保存专题内容
	saveSpecial : function(sid, title, content, ext_data, fn){
		this.postReq(this.mkUrl('admin/specialv2','saveSpecial'), {
			sid : sid,
			title:title,
			content:content,
			ext_data : ext_data
		}, fn)
	},

	
	//获取专题内容
	getSpecial : function(sid, fn){
		this.postReq(this.mkUrl('admin/specialv2','getSpecial'), {
			sid : sid
		}, fn)
	},
	
	
	
	/*
	 *
	 */
	// getFeedInnerCount : function(tipids,lvtuids){
		
	
	// }
	// friendFeed/ajaxget.smpauth
    
    /**
    * 发表或编辑小组的帖子
    */
    saveGroupPost : function(data, fn , cfg) {
        return XwbRequest.postReq(this.jsAPI('groupApi', data.id ? 'topic_edit': 'topic_new'), data, fn , cfg);
    }
	
};


/**
 * @class Xwb.ax.ResponseDefinition
 * 该类定义获得返回内容数据的方式，即封装了底层数据返回的具体结构，外部应用可以以一致的<b>方法</b>读取返回的数据。<br/>
 * 异步返回的JSONP数据格式是前端与后台既定的一个格式，<strong>任何异步请求都要遵循该格式</strong>。<br/>
 * 一般情况下不必直接实现化本类，当{@link Xwb.request}发起的异步请求返回时，回调传递的参数就是本类的实例化对象。
 * <pre><code>
    // response参数即为Xwb.ax.ResponseDefinition类实例
    Xwb.request.q('http://server.com/', {}, function(response){
        if(response.isOk()){
            alert(response.getData());
        }
   });
 </code></pre>
 * @constructor
 * @param {Object} rawData row json data responsed by server
 * @param {Object} requestConfig 连接配置信息
 * @param {XMLHttpRequest|JSONP} connector 发起请求的连接器(ajax:XMLHttpRequest或JSONP:script结点)
 */
XwbRequest.DefaultResponseDefinition = function(rawData, reqCfg, connector){
    this.raw = rawData;
    this.reqCfg = reqCfg;
    if(connector)
        this.connector = connector;
};

XwbRequest.DefaultResponseDefinition.prototype = {
/**
 * 获得该请求发起时的配置信息
 * @return {Object}
 */
    getRequestCfg : function(){
        return this.reqCfg;
    },
/**
 * 获得该请求所使所有连接器(ajax:XMLHttpRequest对象或JSONP:script结点)
 * @return {Object}
 */
    getConnector : function(){
        return this.connector;
    },
    
/**
 * 获得请求原始返回数据，根据请求数据类型的不同返回text文本或json对象
 * @return {Object} jsonData
 */
    getRaw : function(){
        return this.raw;
    },

/**
 * 获得该请求的应用数据
 * @return {Object}
 */
    getData : function(){
        return this.getRaw().rst;
    },

/**
 * 检测服务器数据调用是否成功。
 * 该检测处于服务器成功返回之后，
 * 对客户端提交的请求数据有效性的一种反应。
 * @return {Boolean}
 */
    isOk : function(){
        return !this.getCode();
    },

/**
 * 获得返回码
 * @return {Number}
 */
    getCode : function(){
        return this.getRaw().errno;
    },

/**
 * 获得错误的具体信息。这个错误信息是API默认返回的错误信息，主要给开发人员参考。
 * @return {Object} errorInfo
 */
    getError : function(){
        return this.getRaw().err;
    },
    
/**
 * 从ERRORMAP获得错误码对应信息，返回的信息是面向用户的信息，如果要获得开发人员参考的错误信息，请用{@link #getError}。
 * @param {String} defaultString 如果不存在，返回该字符串。
 * @return {String}
 */
    getMsg : function(def, map){
        var 
            err_code = this.getCode(),
            msg = ERRORMAP[ err_code ];
            
        if(__debug) if( !msg ) console.warn('未定义错误码消息：' + err_code, '@', this.getRaw());
        
        // '系统繁忙，请稍后重试！'
        var emsg = msg || def;
        return ( map ? 
            Util.templ(
                emsg , 
                $.isArray( map ) || typeof map == 'object' ? map : [map]) :emsg )  || this.getError() || ('系统不给力，请稍后再试试吧。');
    },

/**
 * 枚举返回的data数据，只枚举下标为数字的条项。
 * @param {Function} callback
 * @param {Object} scope
 */
    each : function(func, scope){
        var i = 0, data = this.getData();
        for( var item in data ){
            if( isNaN (item) )
                continue;
            if( scope ){
                if( func.call(scope, data[item], i) === false)
                    break;
            } else if( func(data[item], i) === false)
                 break;
            i++;
        }
    }
};


//
//  这里只限定后台返回的错误码，请不要定义其它多余的错误码。
//
var ERRORMAP = XwbRequest.ERRORMAP = X.lang.ERRORMAP;

//
//  为方便处理，所有事件统一有X层发送
//

if(!X.fire)
    X.fire = function(){};
X.request = XwbRequest;

})(window.Xwb);
